package com.javaee.tallybook.service;

import com.javaee.tallybook.mapper.UserMapper;
import com.javaee.tallybook.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("userService")
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public Integer addUser(User user){
        return userMapper.insertUser(user);
    }

    public User getUserByNameAndPwd(String name,String pwd){
        return userMapper.selectUserByNameAndPwd(name,pwd);
    }

    public List<User> getAllUser(){
        return userMapper.selectAllUser();
    }

    /**
     * 用户名已注册则返回true
     * @param name
     * @return
     */
    public Boolean isExist(String name){
        return userMapper.selectName(name) != null;
    }

    public Integer changePwd(String pwd, String name) {
        return userMapper.updatePwd(name,pwd);
    }
}
